package com.example.mymvvmdemo.models.main.fragment.notification.adapter;

import android.content.Context;

import com.example.mymvvmdemo.base.BaseVBAdapter;
import com.example.mymvvmdemo.databinding.ItemNotificationBinding;
import com.example.mymvvmdemo.entity.CommonEntity;
import com.example.mymvvmdemo.models.main.fragment.notification.entity.MessageMessagesEntity;
import com.example.mymvvmdemo.utils.StrUtils;

import java.util.ArrayList;

public class NotificationAdapter extends BaseVBAdapter<MessageMessagesEntity.DataDTO.ResultsDTO, ItemNotificationBinding> {

    private MessageListener listener;

    public void setListener(MessageListener listener) {
        this.listener = listener;
    }

    /**
     * @param context
     */
    public NotificationAdapter(Context context, ArrayList<MessageMessagesEntity.DataDTO.ResultsDTO> list) {
        super(context);
        setDataList(list);
    }

    @Override
    protected void updateData(ItemNotificationBinding bind, MessageMessagesEntity.DataDTO.ResultsDTO item, int position) {

        if (item == null) {
            return;
        }

        //设备id
        int device = item.getDevice();
        bind.tvUser.setText("" + device);

        String topic = item.getTopic();
        if (!StrUtils.isEmpty(topic)) {
            bind.tvContext.setText(topic);
        }

        String created_at = item.getCreated_at();
        if (!StrUtils.isEmpty(created_at)) {
            bind.tvTime.setText(created_at);
        }

        bind.clAll.setOnClickListener(view -> {
            if (listener != null) {
                listener.onClickMessage(position);
            }
        });


    }

    public interface MessageListener {
        void onClickMessage(int position);
    }

}
